#include<iostream>
using namespace std;
#include<vector>
class Solution {
public:
    int dx[4] = { -1, 1, 0, 0 };
    int dy[4] = { 0, 0, -1, 1 };
    vector<vector<int> > flipChess(vector<vector<int> >& A, vector<vector<int> >& f) {
        int n = A.size(), m = A[0].size();
        for (auto& e : f)
        {
            int a = e[0] - 1, b = e[1] - 1;
            for (int k = 0; k < 4; k++)
            {
                int x = dx[k] + a, y = dy[k] + b;
                if (x >= 0 && x < n && y >= 0 && y < m) A[x][y] ^= 1;
            }
        }
        return A;
    }
};
#include<iostream>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;
LL n;
LL arr[N], dp[N];

int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> arr[i];
    for (int i = 3; i <= n; i++)
    {
        dp[i] = max(dp[i - 3] + arr[i - 1], dp[i - 1]);
    }
    cout << dp[n] << endl;
    return 0;
}

#include<iostream>
using namespace std;

const int N = 2010;
int n;
int arr[N];

int bfs()
{
    int left = 1, right = 1;
    int ret = 0;
    while (left <= right)
    {
        ret++;
        int r = right;
        for (int i = left; i <= right; i++)
        {
            r = max(r, arr[i] + i);
            if (r >= n) return ret;
        }
        left = right + 1;
        right = r;
    }
    return -1;
}
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> arr[i];

    cout << bfs() << endl;

    return 0;
}